﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <mutex>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QTimer>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_serialBtn_clicked();
    void on_clearBtn_clicked();

    void SlotTimer();
    void SlotRead();
    void SlotPortError(QSerialPort::SerialPortError);

    void on_refreshSerialBtn_clicked();

    void on_fileSaveBtn_clicked();

private:
    void closePort();
    void refreshSerialPort();
    void writeLog(const char *title, char *buf, int len);
    QString byteArrayToHexStr(const QByteArray &data);
    void writeWndLog(const QString& data);

private:
    Ui::MainWindow *ui;
    QSerialPort *serialPort;
    QSerialPortInfo *serialPortInfo;
    QTimer *timerWnd;

    std::mutex mutexCalcNum;

    quint32 sendNum = 0;
    quint32 recvNum = 0;
    quint32 continuousNum = 0;
    quint32 conNum = 0;
    quint32 overTick = 3000;

    bool isOpen = false;
};

#endif // MAINWINDOW_H
